package com.bdweb.controller;

import com.bdweb.model.USER;
import com.bdweb.pojo.Result;

import com.bdweb.service.impl.UserServiceImpl;
import com.bdweb.utils.commonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Random;

@RestController

public class loginController {
      String username;
    @Autowired   //依赖注入


    UserServiceImpl userService;

    @CrossOrigin(origins = "*")   //设置跨域

    @PostMapping("/login")

    public Result login(  USER user) {
         username=user.getUsername();
        HashMap<String, String> hash = new HashMap<>();
        String uuid = commonUtils.uuid();
        Random random = new Random();
        int userId = random.nextInt(1000);
        hash.put("token", uuid);

        hash.put("userId", userId + "");
        USER user1 = userService.findUser(user.getUsername(), user.getPassword());
        if(user1==null){

            return new Result(100, "success", hash);
        }

        return new Result(200, "success", hash);

        }




    }
